import "package:ct_pa_majordomo/config/theme_vars.dart";
import "package:ct_pa_majordomo/pages/device/lock/near_lock/index.dart";
import "package:ct_pa_majordomo/router/keys.dart";
import "package:ct_pa_majordomo/utils/index.dart";
import "package:ct_pa_majordomo/utils/stacker.dart";
import "package:ct_pa_majordomo/widgets/button/index.dart";
import "package:ct_pa_majordomo/widgets/divider/solid_divider.dart";
import "package:ct_pa_majordomo/widgets/select_group.dart";
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";
import "package:flutter_form_builder/flutter_form_builder.dart";

class AddLock extends StatefulWidget {
  const AddLock({super.key});
  @override
  State<StatefulWidget> createState() => _AddLockState();

}

class _AddLockState extends State<AddLock> {
  final GlobalKey<FormBuilderState> _formKey = GlobalKey<FormBuilderState>();
  FormBuilderState? get _formState => _formKey.currentState;
  String lockName = "";
  String groupValue = "";

  bool checkIsNext () {
    return Utils.isNotEmpty(lockName);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        iconTheme: const IconThemeData(color: Colors.white),
        title: const Text("添加智能锁", style: TextStyle(color: Colors.white),),
        centerTitle: true,
        backgroundColor: ThemeVars.colorPrimaryDark,
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios_new),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ),
      body: ListView(
        padding: const EdgeInsets.symmetric(horizontal: ThemeVars.paddingPage, vertical: 20),
        children: [
          DecoratedBox(
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(12),
              boxShadow: const [ThemeVars.boxShadow],
              color: Colors.white,
            ),
            child: Padding(
              padding: const EdgeInsets.all(16),
              child: FormBuilder(
                key: _formKey,
                child: Column(
                  children: [
                    Row(
                      children: [
                        const Expanded(
                          child: Wrap(
                            crossAxisAlignment: WrapCrossAlignment.center,
                            children: [
                              Text("*", style: TextStyle(color: ThemeVars.colorError),),
                              SizedBox(width: 10,),
                              Text("锁名称", style: TextStyle(fontSize: 16),)
                            ],
                          ),
                        ),
                        SizedBox(
                          width: 200,
                          child: TextFormField(
                            decoration: const InputDecoration(
                              hintText: "请输入",
                              border: InputBorder.none,
                              isDense: true,
                            ),
                            textAlign: TextAlign.right,
                            initialValue: lockName,
                            onChanged: (value) {
                              setState(() {
                                lockName = value;
                              });
                            },
                          ),
                        ),
                      ],
                    ),
                    // const SolidDivider(padding: EdgeInsets.symmetric(vertical: 5),),
                    // Row(
                    //   children: [
                    //     const Expanded(
                    //       child: Wrap(
                    //         crossAxisAlignment: WrapCrossAlignment.center,
                    //         children: [
                    //           Text("*", style: TextStyle(color: ThemeVars.colorError),),
                    //           SizedBox(width: 10,),
                    //           Text("分组", style: TextStyle(fontSize: 16),)
                    //         ],
                    //       ),
                    //     ),
                    //     SizedBox(
                    //       width: 200,
                    //       child: TextFormField(
                    //         decoration: InputDecoration(
                    //           border: InputBorder.none,
                    //           suffixIcon: GestureDetector(
                    //             behavior: HitTestBehavior.opaque,
                    //             onTap: () {
                    //               showSelectGroup(
                    //                 context: context,
                    //                 statusBarHeight: MediaQuery.of(context).padding.top,
                    //                 groupValue: groupValue,
                    //                 onChange: (value) {
                    //                   print(value);
                    //                   setState(() {
                    //                     groupValue = value;
                    //                   });
                    //                 },
                    //               );
                    //             },
                    //             child: Row(
                    //               mainAxisAlignment: MainAxisAlignment.end,
                    //               crossAxisAlignment: CrossAxisAlignment.center,
                    //               children: [
                    //                 Text(groupValue != "" ? groupValue : "请选择", style: const TextStyle(fontSize: 16, color: ThemeVars.colorTextTer,),),
                    //                 const Icon(Icons.arrow_forward_ios, size: 18, color: ThemeVars.colorTextTer,),
                    //               ],
                    //             ),
                    //           ),
                    //         ),
                    //         textAlign: TextAlign.right,
                    //         textAlignVertical: TextAlignVertical.center,
                    //         initialValue: groupValue,
                    //         // onChanged: (value) {
                    //         //   setState(() {
                    //         //     groupValue = value;
                    //         //   });
                    //         // },
                    //       ),
                    //     ),
                    //   ],
                    // ),
                  ],
                ),
              ),
            ),
          ),
          const SizedBox(height: 60,),
          Button(
            type: ButtonType.primary,
            onPressed: checkIsNext() ? () {
              Stacker.pushNamed(Keys.DEVICE_LOCK_NEAR_LOCK, arguments: lockName);
            } : null,
            child: const Text("下一步"),
          ),
        ],
      ),
    );
  }
  
}